package com.juyu.miliao.common.util;

import java.util.HashMap;
import java.util.Map;
import java.util.Random;

/**
 * 赠送礼物会返寻豆
 * 计算返回寻豆倍数概率
 */
public class GiftSpendGiveBeans {
    /**
     * Map<编号,倍数>
     */
    private static final Map<Integer,Integer> giveMap = new HashMap<>();
    static{
        giveMap.put(1,5); //5%
        giveMap.put(2,6); //5%
        giveMap.put(3,7); //10%
        giveMap.put(4,8); //30%
        giveMap.put(5,9); //30%
        giveMap.put(6,10); //10%
        giveMap.put(7,11); //5%
        giveMap.put(8,12); //5%
    }

    /**
     * 返回倍数
     * @return
     */
    public static int getGiveBeansRatio(){
        int temp = 1;
        Random r = new Random();	//随机数生成器
        int num = r.nextInt(100) + 1;    //让随机数在1~100间产生随机数
        if (num <= 5) {        //5%
            temp = giveMap.get(1);
        } else if (num <= 10) {        //5%
            temp = giveMap.get(2);
        } else if (num <= 20) {        //10%
            temp = giveMap.get(3);
        } else if (num <= 50) {        //30%
            temp = giveMap.get(4);
        } else if (num <= 80) {        //30%
            temp = giveMap.get(5);
        } else if (num <= 90) {        //10%
            temp = giveMap.get(6);
        } else if (num <= 95) {        //5%
            temp = giveMap.get(7);
        } else if (num <= 100) {       //5%
            temp = giveMap.get(8);
        }
        return temp;
    }
}
